package com.itheima;

import com.itheima.service.impl.UserServiceImpl;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
 * @author 薛虎
 * @date 2021/1/14 10:56
 */
public class ServerMain {

    public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException {

        //1.启动RMI注册服务,指定端口号
        try {
            LocateRegistry.createRegistry(8888);
        } catch (RemoteException e) {
            e.printStackTrace();
        }


        //2.创建要被访问的远程对象的实例
        UserServiceImpl userService = new UserServiceImpl();


        //3.把远程对象实例注册到RMI注册服务器上
        Naming.bind("rmi://localhost:8888/UserService", userService);

        System.out.println("服务端已启动中....");

    }

}
